package com.jiutong.meipenggang.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;


/**
 * @author Veken
 * @date on 2017/11/22 11:33
 * @describe
 */

public class TestView extends View {
    private Paint paint;
    private int width,height;
    private Context context;
    public TestView(Context context) {
        super(context);
        this.context  = context;
    }

    public TestView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView() {
        paint = new Paint();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width = MeasureSpec.getSize(widthMeasureSpec);
        height = MeasureSpec.getSize(heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //绘制虚线
        PathEffect dashPathEffect = new DashPathEffect(new float[]{10,10, 10, 10}, 0);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(5);
        paint.setPathEffect(dashPathEffect);
        paint.setTextSize(14);
        paint.setColor(Color.WHITE);
        canvas.drawPaint(paint);
        Log.d("宽高","宽=="+width+" 高=="+height);
    }
}
